// 搜索二叉树插入
var insertIntoBST = function(root, val) {
    if (root === null) {
        return new TreeNode(val);
    }
    let pos = root;
    while (pos !== null) {
        if (val < pos.val) {
            if (pos.left === null) {
                pos.left = new TreeNode(val);
                break;
            } else {
                pos = pos.left;
            }
        } else {
            if (pos.right === null) {
                pos.right = new TreeNode(val);
                break;
            } else {
                pos = pos.right;
            }
        }
    }
    return root;
};
var insertIntoBST = function (root, val) {
        const setInOrder = (root, val) => {
            if (root === null) {
                let node = new TreeNode(val);
                return node;
            }
            if (root.val > val)
                root.left = setInOrder(root.left, val);
            else if (root.val < val)
                root.right = setInOrder(root.right, val);
            return root;
        }
        return setInOrder(root, val);
    }
